#define _CRT_SECURE_NO_WARNINGS 1
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;

int main()
{
    int n, m, money[100010];
    scanf("%d %d", &n, &m);
    int max = 0, mn = 0;
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &money[i]);
        max = (max > money[i]) ? max : money[i];
        mn += money[i];
    }
    int target, mid, sum = 0, mon = 0;
    while (max < mn)
    {
        sum = 0;
        mon = 1;
        mid = (max + mn) / 2;
        for (int i = 0; i < n; i++)
        {
            if (sum + money[i] > mid)
            {
                mon++;
                sum = 0;
            }
            sum += money[i];
        }
        if (mon <= m)
        {
            target = mid;
            mn = mid;
        }
        else
            max = mid + 1;
    }
    printf("%d", target);
    return 0;
}